#include "show.h"

uint16_t old_rate;

void show_rate(uint16_t rate)
{
    if (old_rate == rate)
    {
        return;
    }
    LCD_ShowNum(5, 5, (u32)rate, 3, 24, RED);
    old_rate = rate;
}

short wave_buffer[320];
short flagdisp = 0;
unsigned short Data_Pointer;
short Wave_buffer_pre = 0;
short Wave = 0;
byte s = 0;

void show_wave(short data, short damp, short sample)
{
    if (flagdisp <= 0)
    {
        flagdisp = sample;
        Wave = data / damp;
        LCD_DrawLine(Data_Pointer, 120 - wave_buffer[Data_Pointer], Data_Pointer + 1, 120 - wave_buffer[Data_Pointer + 1], BACK_CLOLOR);
        if (Data_Pointer == 318)
        {
            LCD_DrawLine(Data_Pointer, 120 - Wave_buffer_pre, Data_Pointer + 1, 120 - Wave, BACK_CLOLOR);
        }
        else if (s)
        {
            LCD_DrawLine(Data_Pointer, 120 - Wave_buffer_pre, Data_Pointer + 1, 120 - Wave, WAVE_COLOR1);
        }
        else
        {
            LCD_DrawLine(Data_Pointer, 120 - Wave_buffer_pre, Data_Pointer + 1, 120 - Wave, WAVE_COLOR2);
        }
        wave_buffer[Data_Pointer] = Wave_buffer_pre;
        Wave_buffer_pre = Wave;
        if (Data_Pointer < 318)
            Data_Pointer++;
        else
        {
            Data_Pointer = 0;
            s = (s == 0) ? 1 : 0;
        }
    }
    flagdisp--;
}